<?php

namespace App\Model;

class Wx
{
    public static function wxhttpRequest($domain)
    {
// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl=http%3A%2F%2Fbaidu.com&skey=%40crypt_7487cf25_187b432ab9ad3969b6965bb284e42700&deviceid=e367599576115821&pass_ticket=undefined&opcode=2&scene=1&username=@2d398f1df7b03153be2cd6703fc76704
        $url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl=http%3A%2F%2F'.$domain.'&skey=%40crypt_7487cf25_187b432ab9ad3969b6965bb284e42700&deviceid=e367599576115821&pass_ticket=undefined&opcode=2&scene=1&username=@2d398f1df7b03153be2cd6703fc76704';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //换网页版微信cookie
		$user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36';
		$cookie = 'webwxuvid=df683ea1e7dd8c0d7f9047a469cff88b8e2dc1dad45e0449298274f16282a22ebac97ea9c061d6cbab2e3ee24f3bba64; pgv_pvid=6464797600; pgv_pvi=1813605376; pac_uid=0_5d0b33b9a1c04; RK=ptKl332JYG; ptcz=d3bf7ff7c13784c3106d04cbbc4162b1d341a8396e716c78d387d22b4ebc124f; XWINDEXGREY=0; wxuin=1423721840; mm_lang=zh_CN; MM_WX_NOTIFY_STATE=1; MM_WX_SOUND_STATE=1; wxsid=OjYuK7ZeMrlXESbc; webwx_data_ticket=gSflm5ngVeHNFr9jw7Fvc8pS; webwx_auth_ticket=CIsBEI+OwpkLGoABnIt53b26HsJVqRZ58JYc/OQq7RmMx22+ww0C4i827i5Vz0F3/ygjBDWq+P8+kWdmZrAeb/aaEGifpzOchxK19J280xpSVCojjbYUo+p8k5HKhfvfZu7IDjNh1/bFZa7l5Qpybjp+yoKhJjUVNsrOtLp8JOL2cww1xLBqNRmLsVk=; login_frequency=1; last_wxuin=1423721840; wxloadtime=1567998968_expired; wxpluginkey=1567987277';
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        $output = curl_exec($ch);
        // $request_header = curl_getinfo($ch,CURLINFO_HEADER_OUT);
        curl_close($ch);
        // dump($request_header);
        $output_arr = json_decode($output, true);
        if (strpos($output_arr['FullURL'], 'weixin110.qq.com')) {
            // file_put_contents('./wxurls.log', '检测域名被封记录:'.date('Y-m-d : h:i:sa',time()).'检查url:'.$domain."\n", FILE_APPEND);
            return ['status' => 2, 'errmsg' => '系统sys1检测域名被封', 'url' => $domain];
        } 
        // elseif (empty($output_arr['FullURL']) || $output_arr == null) {

        //     return ['status' => 3, 'errmsg' => '系统sys1检测失效,请联系管理员', 'url' => $domain];
        // } 
        else {
            // 写入本地日志 每小时创建一个文件
            // file_put_contents('./logs/requestMsg'.date('YmdH',time()).'.log', '检查系统日志记录:'.date('Y-m-d : h:i:sa',time()).'检查url:'.$domain."\n", FILE_APPEND);
            return ['status' => 1, 'errmsg' => '系统sys1发送信息', 'url' => $domain];
        }
    }
}
